package com.ali.common;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class ShaUtil {
    private static final String ALGORITHM_SHA = "SHA";
    private static final String ALGORITHM_SHA_1 = "SHA-1";
    private static final String ALGORITHM_SHA_224 = "SHA-224";
    private static final String ALGORITHM_SHA_256 = "SHA-256";
    private static final String ALGORITHM_SHA_384 = "SHA-384";
    private static final String ALGORITHM_SHA_512 = "SHA-512";

    /**
     * SHA加密
     */
    public static String encrypt(String content) {
        byte[] contentByte = content.getBytes(StandardCharsets.UTF_8);

        try {
            MessageDigest messageDigest = MessageDigest.getInstance(ALGORITHM_SHA);
            byte[] digestByte = messageDigest.digest(contentByte);
            return HexUtil.encrypt(digestByte);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}